﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
using Etong.Web;
/// <summary>
///BaseSearchShow 的摘要说明
/// </summary>
public abstract class BaseSearchShow:ISearchTypeField
{
	public BaseSearchShow()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}
    protected abstract IEnumerable<Control> GetSearchContrls(ConfigColumns cCol);

    #region ISearchTypeField 成员

    public IEnumerable<Control> GetSearchFieldControls(ConfigColumns cCol)
    {
        List<Control> Controls = new List<Control>();
        Literal left = new Literal();
        left.Text = "<li>";
        Literal right = new Literal();
        right.Text = "</span></li>";
        Controls.Add(left);
        Literal lit = new Literal();
        lit.Text = "<span class='SearchTitleSpan'>"+cCol.SearchShowName+"</span><span class='SearchFieldSpan'>";
        Controls.Add(lit);
        
        foreach (Control ctrl in GetSearchContrls(cCol))
        {
            Controls.Add(ctrl);
        }

        if (cCol.SearchShowType == SearchShowType.Text || cCol.SearchShowType== SearchShowType.DateTime)
        {
            if (cCol.SearchShowRange)
            {
                RangeValidator rangeV = new RangeValidator();
                rangeV.ID = cCol.ColumnName + "_range";
                rangeV.ValidationGroup = "Search";
                rangeV.MinimumValue = cCol.SearchShowRangeMinValue;
                rangeV.MaximumValue = cCol.SearchShowRangeMaxValue;
                rangeV.ControlToValidate = cCol.ColumnName + "_SearchShow";
                rangeV.ErrorMessage = rangeV.MinimumValue + " - " + rangeV.MaximumValue;
                rangeV.SetFocusOnError = true;
                rangeV.Type = cCol.SearchShowRangeType;
                rangeV.Display = ValidatorDisplay.Dynamic;

                Controls.Add(rangeV);
            }
            if (cCol.SearchShowRegExp)
            {
                RegularExpressionValidator regV = new RegularExpressionValidator();
                regV.ID = cCol.ColumnName + "_regexp";
                regV.ControlToValidate = cCol.ColumnName + "+SearchShow";
                regV.SetFocusOnError = true;
                regV.Display = ValidatorDisplay.Dynamic;
                regV.ValidationGroup = "Search";
                regV.ValidationExpression = cCol.SearchShowRegExpText;
                regV.ErrorMessage = cCol.SearchShowRegExpErrMessage;

                Controls.Add(regV);
            }
        }
        Controls.Add(right);
        return Controls;
    }

    #endregion
    
}
